home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7339 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  41 lines

  1. Path: sun001.spd.dsccc.com!spd!jmccarty
  2. From: jmccarty@spd.dsccc.com (Mike McCarty)
  3. Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
  4. Subject: Re: Access carry flag from C
  5. Date: 22 Feb 1996 19:58:44 GMT
  6. Organization: DSC Communications Corporation, Plano, Texas USA
  7. Message-ID: <4gihtk$33k@sun001.spd.dsccc.com>
  8. References: <Dn1C9z.DGv.0.net@indra.com> <1996Feb1922.17.19.879@koobera.math.uic.edu>
  9. NNTP-Posting-Host: aplo139.spd.dsccc.com
  10.  
  11. In article <1996Feb1922.17.19.879@koobera.math.uic.edu>,
  12. D. J. Bernstein <djb@koobera.math.uic.edu> wrote:
  13. )Steve Sullivan <sullivan@indra.com> wrote:
  14. )>    i = j + k;
  15. )>    if (overflowed) ....;
  16. )
  17. )A smart compiler will optimize ``if (i < j)''---I'm assuming here that
  18. )all variables are unsigned---into a test of the carry bit.
  19.  
  20. Depends on which (if any) of i and j are unsigned whether that is even
  21. the correct test. Unsigned overflow should check the carry bit. Signed
  22. overflow must test for a carry out of a different bit. Also, your
  23. statement actually depends on having complement arithmetic, rather than
  24. signed magnitude. This is a difficult problem, and such checks are
  25. going to be s-l-o-w. There are machines which provide hardware traps on
  26. integer overflow.
  27.  
  28. )(I've been saying for years that every compiler should provide a
  29. )_documented_ idiom for every possible machine-language operation.)
  30. )
  31. )---Dan
  32.  
  33.  
  34. HMMMM.
  35.  
  36. Mike
  37. ----
  38. char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
  39.  
  40. I don't speak for DSC.         <- They make me say that.
  41.